package leetcode.stacklist;

import leetcode.list._160;

import java.util.Stack;

/**
 * 232. 用栈实现队列
 */
public class _232 {

    static class MyQueue {
        Stack<Integer> inputStack = new Stack<>();
        Stack<Integer> outputStack = new Stack<>();

        public MyQueue() {
        }


        public void push(int x) {
            inputStack.push(x);
        }

        public int pop() {
            if (outputStack.empty()) {
                while (!inputStack.empty()) {
                    outputStack.push(inputStack.pop());
                }
            }
            return outputStack.pop();

        }

        public int peek() {
            if (outputStack.empty()) {
                while (!inputStack.empty()) {
                    outputStack.push(inputStack.pop());
                }
            }
            return outputStack.peek();
        }

        public boolean empty() {
            return inputStack.empty() && outputStack.empty();
        }

    }


}
